package org.dg.dgimg.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import jakarta.servlet.http.HttpServletRequest;
import org.dg.dgimg.entity.User;
import org.dg.dgimg.utils.RedisUtils;
import org.dg.dgimg.utils.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  Img前端控制器
 *
 * @author DG
 * @since 2024-06-25
 */
@RestController
@RequestMapping("/img")
public class ImgController {

    @Autowired
    RedisUtils redisUtils;

    @GetMapping(value = "/index", produces = "application/json;charset=UTF-8")
    public String list(HttpServletRequest request) {
        String token = (String) request.getAttribute("UUID");
        System.out.println(token);
        User user = JSON.parseObject(redisUtils.getkey(token), User.class);
        System.out.println(user);
        return JSONObject.toJSONString(RestBean.success(user));
    }

}
